<template>
  <div id="app" class="h-full">
    <keep-alive>
      <router-view/>
    </keep-alive>
  </div>
</template>

<script>
import Global from "./Global";
import "./static/stylus/global.styl"
export default {
  name: 'app',
  created() {
    let isLogin = sessionStorage.getItem('userId');
    if(!isLogin){
      return this.$router.push({path:'/login'});
    }else {
      this.$http({
        url: '/refresh',
        method: 'POST',
        data: this.$qs.stringify({'userId': sessionStorage.getItem("userId")})
      }).then((res) => {
        // 得到权限菜单
        let permissionsrouters = res.routers;
        // 格式化权限菜单，将component中的string 转为 component对象
        // 将路由列表添加到全局
        Global.routerList = permissionsrouters[0].children;
        //循环遍历动态路由表的每一个路由refresh
        Global.generateRouterDate(permissionsrouters);
        // 动态添加路由;
        this.$router.addRoutes(permissionsrouters);
        //跳转到应用界面
        this.$router.push('/main/dashboard')
      })
    }
  },
  components: {
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  overflow: hidden;
}
</style>
